//////////////////////////////////////////////////////////////////////////
#include "CvStructs.h"
//////////////////////////////////////////////////////////////////////////
#pragma once
#pragma managed
//////////////////////////////////////////////////////////////////////////
using namespace System;
using namespace System::Runtime::InteropServices;
//////////////////////////////////////////////////////////////////////////
NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// spatial and central moments
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Moments
{
	/// <summary>
	/// spatial moments
	/// </summary>
	double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;
	/// <summary>
	/// central moments
	/// </summary>
	double mu20, mu11, mu02, mu30, mu21, mu12, mu03;
	/// <summary>
	/// m00 != 0 ? 1/sqrt(m00) :
	/// </summary>
	double inv_sqrt_m00;
};

/// <summary>
/// Hu invariants
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HuMoments
{
	/// <summary>
	/// Hu invariant
	/// </summary>
	double hu1, hu2, hu3, hu4, hu5, hu6, hu7;
};

/// <summary>
/// Connected Component
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ConnectedComp
{
	/// <summary>
	/// area of the connected component
	/// </summary>
	double area;
	/// <summary>
	/// average color of the connected component
	/// </summary>
	Scalar value;
	/// <summary>
	/// ROI of the component
	/// </summary>
	Rect rect;
	/// <summary>
	/// optional component boundary
	/// (the contour might have child contours corresponding to the hole
	/// </summary>
	IntPtr contour;
};

/// <summary>
/// Freeman chain reader state
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ChainPtReader
{
	/// <summary>
	/// seq_reader_fields
	/// </summary>
	SeqReaderFields seq_reader_fields;
	/// <summary>
	/// code
	/// </summary>
	char code;
	/// <summary>
	/// point
	/// </summary>   
	Point2D32s pt;
	/// <summary>
	/// deltas
	/// </summary>
	inline_array2d<schar, 2, 8> deltas;
};

/// <summary>
/// Contour tree header
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ContourTree
{
	/// <summary>
	/// sequence_fields
	/// </summary>
	SequenceFields sequence_fields;
	/// <summary>
	/// the first point of the binary tree root segment
	/// </summary>
	Point2D32s p1;
	/// <summary>
	/// the last point of the binary tree root segmen
	/// </summary>
	Point2D32s p2;
};

/// <summary>
/// Finds a sequence of convexity defects of given contour
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ConvexityDefect
{
	/// <summary>
	/// point of the contour where the defect begins
	/// </summary>
	IntPtr start;
	/// <summary>
	/// point of the contour where the defect ends
	/// </summary>
	IntPtr end;
	/// <summary>
	/// the farthest from the convex hull point within the defect
	/// </summary>
	IntPtr depth_point;
	/// <summary>
	/// distance between the farthest point and the convex hul
	/// </summary>
	float depth;
};

[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Subdiv2DEdge
{
	size_t Value;
};

/// <summary>
/// QuadEdge2DFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct QuadEdge2DFields
{
	/// <summary>
	/// Flags
	/// </summary>
	int flags;
	/// <summary>
	/// Point2D32ss
	/// </summary>
	inline_array_ex<IntPtr, sizeof(size_t), 4> pt;
	/// <summary>
	/// Next
	/// </summary>
	inline_array_ex<Subdiv2DEdge, sizeof(size_t), 4> next;
};

/// <summary>
/// Subdiv2DPoint
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Subdiv2DPointFields
{
	/// <summary>
	/// Flags
	/// </summary>
	int flags;
	/// <summary>
	/// First
	/// </summary>
	Subdiv2DEdge first;
	/// <summary>
	/// Point2D32s
	/// </summary>
	Point2D32f pt;
};

/// <summary>
/// Subdiv2DPoint
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct QuadEdge2D
{
	QuadEdge2DFields fields;
};

/// <summary>
/// Subdiv2DPoint
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Subdiv2DPoint
{
	Subdiv2DPointFields fields;
};

/// <summary>
/// Subdiv2DFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Subdiv2DFields
{
	/// <summary>
	/// graph_fields
	/// </summary>
	GraphFields graph_fields;
	/// <summary>
	/// quad_edges
	/// </summary>
	int quad_edges;
	/// <summary>
	/// is_geometry_valid
	/// </summary>
	int is_geometry_valid;
	/// <summary>
	/// recent_edge
	/// </summary>
	Subdiv2DEdge recent_edge;
	/// <summary>
	/// topleft
	/// </summary>
	Point2D32f topleft;
	/// <summary>
	/// bottomright
	/// </summary>
	Point2D32f bottomright;
};

/// <summary>
/// Subdiv2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Subdiv2D
{
	Subdiv2DFields fields;
};

/// <summary>
/// Matrix3
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Matrix3
{
	/// <summary>
	/// m
	/// </summary>
	inline_array2d<float, 3, 3> m;
};

/// <summary>
/// DistanceFunction
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="user_param"></param>
/// <returns></returns>
[UnmanagedFunctionPointerAttribute(CallingConvention::Cdecl)]
public delegate float DistanceFunction(IntPtr a, IntPtr b, IntPtr user_param);

/// <summary>
/// ConDensation
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ConDensation
{
	int MP;
	int DP;
	/// <summary>
	/// Matrix of the linear Dynamics system
	/// </summary>
	IntPtr DynamMatr;
	/// <summary>
	/// Vector of State
	/// </summary>
	IntPtr State;
	/// <summary>
	/// Number of the Samples
	/// </summary>
	int SamplesNum;
	/// <summary>
	/// arr of the Sample Vectors
	/// </summary>
	IntPtr flSamples;
	/// <summary>
	/// temporary array of the Sample Vectors
	/// </summary>
	IntPtr flNewSamples;
	/// <summary>
	/// Confidence for each Sample
	/// </summary>
	IntPtr flConfidence;
	/// <summary>
	/// Cumulative confidence
	/// </summary>
	IntPtr flCumulative;
	/// <summary>
	/// Temporary vector
	/// </summary>
	IntPtr Temp;
	/// <summary>
	/// RandomVector to update sample set
	/// </summary>
	IntPtr RandomSample;
	/// <summary>
	/// Array of structures to generate random vector
	/// </summary>
	IntPtr RandS;
};

/// <summary>
/// standard Kalman filter (in G:: Welch' and G:: Bishop's notation):
/// x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
/// z(k)=H*x(k)+v(k),   p(v)~N(0,R)
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Kalman
{
	/// <summary>
	/// number of measurement vector dimensions
	/// </summary>
	int MP;
	/// <summary>
	/// number of state vector dimensions
	/// </summary>
	int DP;
	/// <summary>
	/// number of control vector dimensions
	/// </summary>
	int CP;
	/// <summary>
	/// =state_pre->data::fl
	/// </summary>
	IntPtr PosterState;
	/// <summary>
	/// =state_post->data::fl
	/// </summary>
	IntPtr PriorState;
	/// <summary>
	/// =transition_matrix->data::fl
	/// </summary>
	IntPtr DynamMatr;
	/// <summary>
	/// =measurement_matrix->data::fl
	/// </summary>
	IntPtr MeasurementMatr;
	/// <summary>
	/// =measurement_noise_cov->data::fl
	/// </summary>
	IntPtr MNCovariance;
	/// <summary>
	/// =process_noise_cov->data::fl
	/// </summary>
	IntPtr PNCovariance;
	/// <summary>
	/// =gain->data::fl
	/// </summary>
	IntPtr KalmGainMatr;
	/// <summary>
	/// =error_cov_pre->data::fl
	/// </summary>
	IntPtr PriorErrorCovariance;
	/// <summary>
	/// =error_cov_post->data::fl
	/// </summary>
	IntPtr PosterErrorCovariance;
	/// <summary>
	/// temp1->data::fl
	/// </summary>
	IntPtr Temp1;
	/// <summary>
	/// temp2->data::fl
	/// </summary>
	IntPtr Temp2;
	/// <summary>
	/// predicted state (x'(k)):
	/// x(k)=A*x(k-1)+B*u(k)
	/// </summary>
	IntPtr state_pre;
	/// <summary>
	/// corrected state (x(k)):
	/// x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
	/// </summary>
	IntPtr state_post;
	/// <summary>
	/// state transition matrix (A)
	/// </summary>
	IntPtr transition_matrix;
	/// <summary>
	/// control matrix (B)
	/// (it is not used if there is no control)
	/// </summary>
	IntPtr control_matrix;
	/// <summary>
	/// measurement matrix (H)
	/// </summary>
	IntPtr measurement_matrix;
	/// <summary>
	/// process noise covariance matrix (Q)
	/// </summary>
	IntPtr process_noise_cov;
	/// <summary>
	/// measurement noise covariance matrix (R)
	/// </summary>
	IntPtr measurement_noise_cov;
	/// <summary>
	/// priori error estimate covariance matrix (P'(k)):
	/// P'(k)=A*P(k-1)*At + Q)
	/// </summary>
	IntPtr error_cov_pre;
	/// <summary>
	/// Kalman gain matrix (K(k)):
	/// K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
	/// </summary>
	IntPtr gain;
	/// <summary>
	/// posteriori error estimate covariance matrix (P(k)):
	/// P(k)=(I-K(k)*H)*P'(k)
	/// </summary>
	IntPtr error_cov_post;
	/// <summary>
	/// temporary matrices
	/// </summary>
	IntPtr temp1;
	IntPtr temp2;
	IntPtr temp3;
	IntPtr temp4;
	IntPtr temp5;
};

/// <summary>
/// HarrWeight
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HarrWeight
{
	Rect r;
	float weight;
};

/// <summary>
/// HaarFeature
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HaarFeature
{
	int tilted;
	inline_array_ex<HarrWeight, sizeof(float) + sizeof(int) * 4, CV_HAAR_FEATURE_MAX> rect;
};

/// <summary>
/// HaarClassifier
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HaarClassifier
{
	int count;
	IntPtr haar_feature;
	IntPtr threshold;
	IntPtr left;
	IntPtr right;
	IntPtr alpha;
};

/// <summary>
/// HaarStageClassifier
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HaarStageClassifier
{
	int count;
	float threshold;
	IntPtr classifier;
	int next;
	int child;
	int parent;
};

/// <summary>
/// HidHaarClassifierCascade;
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HidHaarClassifierCascade
{
};

/// <summary>
/// HaarClassifierCascade
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct HaarClassifierCascade
{
	int flags;
	int count;
	Size2D32s orig_window_size;
	Size2D32s real_window_size;
	double scale;
	IntPtr stage_classifier;
	IntPtr hid_cascade;
};

/// <summary>
/// AvgComp
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct AvgComp
{
	Rect rect;
	int neighbors;
};
//////////////////////////////////////////////////////////////////////////
NAMESPACE_END
//////////////////////////////////////////////////////////////////////////